import axios from "axios";
import store from "../store/index";
// 创建axios示例
var service = axios.create({
    timeout: 30000
});

// 请求拦截
service.interceptors.request.use(
    //成功的请求拦截
    function (config) {
        config.headers.post = { "Content-Type": "application/json;charset=UTF-8" };
        if (store.state.token) {
            config.headers.post["token"] = store.state.token;
            config.headers.get["token"] = store.state.token;
        }
        return config;
    },
    // 失败的请求拦截
    function (error) {
        return Promise.reject(error);
    }
);
// 相应拦截
service.interceptors.response.use(
    function (response) {
        return response;
    },
    function (error) {
        return Promise.reject(error);
    }
);
export default service;
